package com.view;

import java.util.ArrayList;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

import com.adpter.JobListOrgInfoAdapter;
import com.android.ocean.util.common.StringUtil;
import com.android.ocean.view.XListView;
import com.android.ocean.view.XListView.IXListViewListener;
import com.http.JobListSingleOrgCurrentTask;
import com.matang.R;
import com.modle.JobStruct;
import com.util.AppUtil;

/**
 * 
 * @ClassName:XJobSigleOrgCurrentView
 * @Description:TODO机构信息中，当前发布的招聘信息
 * @author zhuw
 * @date 2013-8-24 下午4:09:19
 */
public class XJobSigleOrgCurrentView extends BaseFrameLayout implements
		IXListViewListener, JobListSingleOrgCurrentTask.CallBack {
	ArrayList<JobStruct> dataList = new ArrayList<JobStruct>();
	int currentPage = 1;
	JobListOrgInfoAdapter adapter;
	XListView listView;
	String userID;// 获取内容的栏目ID
	String searType;// 搜索排序方式

	public XJobSigleOrgCurrentView(Context context) {
		super(context);
		init(context);
	}

	public XJobSigleOrgCurrentView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}

	public XJobSigleOrgCurrentView(Context context, AttributeSet attrs,
			int defStyle) {
		super(context, attrs, defStyle);
		init(context);
	}

	private void init(Context ctx) {
		this.context = ctx;
		View view = LayoutInflater.from(ctx).inflate(
				R.layout.l_merge_xlist_conlist, this);
		listView = (XListView) view.findViewById(R.id.con_listview);
		listView.setPullLoadEnable(false);
		listView.setPullRefreshEnable(false);
		listView.setXListViewListener(this);
		listView.setRefreshTime(StringUtil.getFreshTime());
		loadingView = (View) view.findViewById(R.id.loading_view);
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> adt, View arg1, int pos,
					long arg3) {
				AppUtil.jobSwitch(context, dataList.get(pos));
			}
		});

	}

	public void initData(String userID) {
		this.userID = userID;
		flushData();
		loadConList();
	}

	/**
	 * 加载数据
	 */
	private void loadConList() {
		// showLoading(loadingView);
		new JobListSingleOrgCurrentTask(this).execute(this.userID);

	}

	/**
	 * 此控件可以复用，当再次initConlistCatID或刷新前时需要先清除数据
	 */
	private void flushData() {
		// currentPage = 1;
		// listView.setAdapter(null);
		// listView.setPullLoadEnable(false);
		// listView.setRefreshTime(StringUtil.getFreshTime());
		// dataList.clear();
	}

	@Override
	public void onRefresh() {
		// flushData();
		// loadConList();
	}

	@Override
	public void onLoadMore() {
		currentPage++;
		loadConList();
	}

	private void fillList() {

		if (StringUtil.isListNull(dataList)) {
			AppUtil.tsMsg(context, "无数据...");
		} else {
			adapter = new JobListOrgInfoAdapter(dataList, context);
			listView.setAdapter(adapter);
		}
	}

	@Override
	public void procError(String msg) {
		dismissProgressDialog();
		AppUtil.tsMsg(context, msg);

	}

	@Override
	public void procJobSingleOrgCurrentList(ArrayList<JobStruct> dataList) {
		dismissProgressDialog();
		this.dataList = dataList;
		fillList();

	}
}
